#ifndef RICHTEXTCHATLOG_H_
#define RICHTEXTCHATLOG_H_

#include "../StdUserInterfaceModule/interfaces/iChatLog.h"
#include "../StdUserInterfaceModule/interfaces/iSmileyThemeManager.h"
#include <wx/richtext/richtextctrl.h>
#include "../../core/Impp.h"
#include <wx/event.h>

namespace Impp
{



class RichTextChatLog : public iChatLog, public wxEvtHandler
{
private:
	class LogAction{
	public:
		LogAction(){};
		virtual ~LogAction(){};
	};
	class LogStatusMessageAction : public LogAction{
	public:
		Status status;
		wxString statusMsg;
	};
	class LogMessageAction : public LogAction{
	public:
		wxDateTime time;
		Buddy* sender;
		wxString msg;
		bool in;
		bool isHistory;
		ActionId id;
	};
	class LogMarkMessageAction : public LogAction{
	public:
		MessageCallbackEvent* event;
	};

	class LogScollToEndAction : public LogAction{

	};

private:
	Buddy* buddy;
	wxRichTextCtrl* log;
	int smileyCount;
	iSmileyThemeManager* smileys;
	wxBitmap msgNormal;
	wxBitmap msgError;
	wxBitmap msgUnknown;
	std::vector<LogAction*> actions;
	int locks;

public:
	RichTextChatLog();
	virtual ~RichTextChatLog();

	void create(Buddy* buddy, wxWindow* parent, int id);
	void writeStatusMessage(const Status & newStatus, const wxString & statusMsg);
	void writeMessage(const wxDateTime & time, Buddy* sender,const wxString & msg, bool in, bool isHistory, const ActionId & id = -1);
	void markMessage(MessageCallbackEvent event);
	void scrollToEnd();
	wxWindow* getWindow();
	void clear();
	void onIdleEvent(wxIdleEvent & event);
	void freeze();
	void thaw();

private:
	void doWriteStatusMessage(LogStatusMessageAction* action);
	void doWriteMessage(LogMessageAction* action);
	void doMarkMessage(LogMarkMessageAction* action);
	void doScrollToEnd();

	void writeParsedText(const wxString & text);

};


class StdRichTextChatLogModule : public iChatLogFactory{

	DECLARE_DYNAMIC_CLASS(StdRichTextChatLogModule)

public:
	StdRichTextChatLogModule(){};
	virtual ~StdRichTextChatLogModule(){};

	void moduleInit(){};
	void moduleDestroy(){};

	iChatLog* newChatLog(Buddy* buddy, wxWindow* parent, int id){
		RichTextChatLog* chatLog = new RichTextChatLog();
		chatLog->create(buddy,parent,id);
		return chatLog;
	}

};

}

#endif /*RICHTEXTCHATLOG_H_*/
